home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / circuits / irsim_ta.z / irsim_ta / irsim / src / ana11 / deltaT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-13  |  4.8 KB  |  241 lines

  1. /*
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     *********************************************************************
  13.  */
  14.  
  15. #include "ana.h"
  16. #include "ana_glob.h"
  17. #include "graphics.h"
  18.  
  19.  
  20. public TimeType FindPreviousEdge( t, tm )
  21.   Trptr              t;
  22.   register TimeType  tm;
  23.   {
  24.     register hptr      h;
  25.     register int       val;
  26.     register TimeType  edgeT;
  27.  
  28.     edgeT = tims.start;
  29.     if( IsVector( t ) )
  30.       {
  31.     register int  i;
  32.  
  33.     for( i = t->n.vec->nbits - 1; i >= 0; i-- )
  34.       {
  35.         h = t->cache[i].wind;
  36.         val = h->val;
  37.         while( h->time <= tm )
  38.           {
  39.         if( val != h->val )
  40.           {
  41.             val = h->val;
  42.             if( h->time > edgeT )
  43.             edgeT = h->time;
  44.           }
  45.         NEXTH( h, h );
  46.           }
  47.       }
  48.       }
  49.     else
  50.       {
  51.     h = t->cache[0].wind;
  52.     val = h->val;
  53.     while( h->time <= tm )
  54.       {
  55.         if( val != h->val )
  56.           {
  57.         val = h->val;
  58.         edgeT = h->time;
  59.           }
  60.         NEXTH( h, h );
  61.       }
  62.       }
  63.     return( edgeT );
  64.   }
  65.  
  66.  
  67. public TimeType FindNextEdge( t, tm )
  68.   Trptr              t;
  69.   register TimeType  tm;
  70.   {
  71.     register hptr      h, p;
  72.     register int       val;
  73.     register TimeType  edgeT, endT;
  74.  
  75.     endT = edgeT = min( tims.end, tims.last );
  76.     if( IsVector( t ) )
  77.       {
  78.     register int  i;
  79.  
  80.     for( i = t->n.vec->nbits - 1; i >= 0; i-- )
  81.       {
  82.         p = h = t->cache[i].wind;
  83.         while( h->time <= tm )
  84.           {
  85.         p = h;
  86.         NEXTH( h, h );
  87.           }
  88.         val = p->val;
  89.         while( h->time <= endT )
  90.           {
  91.         if( val != h->val )
  92.           {
  93.             if( h->time < edgeT )
  94.             edgeT = h->time;
  95.             break;
  96.           }
  97.         NEXTH( h, h );
  98.           }
  99.       }
  100.       }
  101.     else
  102.       {
  103.     p = h = t->cache[0].wind;
  104.     while( h->time <= tm )
  105.       {
  106.         p = h;
  107.         NEXTH( h, h );
  108.       }
  109.     val = p->val;
  110.     while( h->time <= endT )
  111.       {
  112.         if( val != h->val )
  113.           {
  114.         edgeT = h->time;
  115.         break;
  116.           }
  117.         NEXTH( h, h );
  118.       }
  119.       }
  120.     return( edgeT );
  121.   }
  122.  
  123.  
  124. private void WaitForRelease()
  125.   {
  126.     XEvent  e;
  127.     
  128.     GrabMouse( window, ButtonPressMask | ButtonReleaseMask, None );
  129.  
  130.     do
  131.     XNextEvent( display, &e );
  132.     while( e.type != ButtonRelease );
  133.  
  134.     XUngrabPointer( display, CurrentTime );
  135.   }
  136.  
  137.  
  138. private    Trptr       t1;
  139. private Coord       x1;
  140. private TimeType    time1;
  141. private void        SetEdge2();
  142.  
  143.  
  144. private void Terminate( cancel )
  145.   int  cancel;
  146.   {
  147.     if( cancel )
  148.     PRINT( "(canceled: click on a trace)" );
  149.     SendEventTo( NULL );
  150.     XDefineCursor( display, window, cursors.deflt );
  151.     RestoreScroll();
  152.   }
  153.  
  154.  
  155. private void SetEdge1( ev )
  156.   XButtonEvent  *ev;
  157.   {
  158.     TimeType  tm;
  159.  
  160.     if( ev == NULL )
  161.       {
  162.     Terminate( FALSE );
  163.     return;
  164.       }
  165.  
  166.     if( ev->type != ButtonPress )
  167.     return;
  168.     
  169.     t1 = GetYTrace( ev->y );
  170.     tm = XToTime( ev->x );
  171.     if( t1 == NULL or tm < 0 )
  172.       {
  173.     Terminate( TRUE );
  174.     return;
  175.       }
  176.     time1 = FindPreviousEdge( t1, tm );
  177.     x1 = TimeToX( time1 );
  178.     PRINTF( "%.1f", d2ns( time1 ) );
  179.  
  180.     FillAREA( window, x1 - 1, t1->top, 3, t1->bot - t1->top + 1, gcs.hilite );
  181.     WaitForRelease();
  182.     FillAREA( window, x1 - 1, t1->top, 3, t1->bot - t1->top + 1, gcs.unhilite);
  183.  
  184.     PRINT( " | t2 = " );
  185.     XDefineCursor( display, window, cursors.right );
  186.     SendEventTo( SetEdge2 );
  187.   }
  188.  
  189.  
  190. private void SetEdge2( ev )
  191.   XKeyEvent  *ev;
  192.   {
  193.     TimeType  time2, diff;
  194.     Trptr     t2;
  195.     Coord     x2, y1, y2;
  196.  
  197.     if( ev == NULL )
  198.       {
  199.     Terminate( FALSE );
  200.     return;
  201.       }
  202.  
  203.     if( ev->type != ButtonPress )
  204.     return;
  205.  
  206.     t2 = GetYTrace( ev->y );
  207.     time2 = XToTime( ev->x );
  208.     if( t2 == NULL or time2 < 0 )
  209.       {
  210.     Terminate( TRUE );
  211.     return;
  212.       }
  213.     time2 = FindNextEdge( t2, time2 );
  214.     x2 = TimeToX( time2 );
  215.  
  216.     if( time2 < time1 )
  217.     diff = time1 - time2;
  218.     else
  219.     diff = time2 - time1;
  220.  
  221.     PRINTF( "%.1f | diff = %.1f", d2ns(time2), d2ns(diff) );
  222.  
  223.     y1 = (t1->top + t1->bot) / 2;
  224.     y2 = (t2->top + t2->bot) / 2;
  225.     XDrawLine( display, window, gcs.hilite, x1, y1, x2, y2 );
  226.     WaitForRelease();
  227.     XDrawLine( display, window, gcs.unhilite, x1, y1, x2, y2 );
  228.  
  229.     Terminate( FALSE );
  230.   }
  231.  
  232.  
  233. public void DeltaT( s )
  234.   char *s;            /* menu string => ignore it */
  235.   {
  236.     PRINT( "\nt1 = " );
  237.     SendEventTo( SetEdge1 );
  238.     XDefineCursor( display, window, cursors.left );
  239.     DisableScroll();
  240.   }
  241.